#!/usr/bin/env python
#coding:utf-8
#一个检查正则表达式的小工具。
import re
import sys
def main(res, string):
    index = 0
    p = re.compile(r'%s' % res)
    for m in p.finditer(string):
        if m:
            print m.group()
            index += 1
        else:
            #print '无'
            sys.exit()
    print '共查找到%s个匹配项!' % index

def usage():
    print "Usage: python re1.py [re] [word(s)]"
    
if __name__ == '__main__':
    if len(sys.argv) == 1:
        usage()
        sys.exit()
    res = sys.argv[1]
    string = sys.argv[2]
    main(res, string)
